﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietPremier.Areas.AdminCP.Models;

namespace VietPremier.Areas.AdminCP.Controllers
{
    public class AdminTravelInformationController : Controller
    {
        //
        // GET: /AdminCP/AdminTravelInformation/

        #region "Edit"
        public ActionResult Edit()
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                TravelInformation model = new TravelInformation();

                EntityTravelInfo travelInfo = db.EntityTravelInfos.FirstOrDefault();
                model.Id = travelInfo.Id;
                model.Description = travelInfo.Description;
                model.Titletag = travelInfo.Titletag;
                model.Meta_description = travelInfo.Meta_description;
                model.Meta_keyword = travelInfo.Meta_keyword;

                return View(model);
            }
            
        }

        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Edit(TravelInformation model)
        {

            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                //check Id 
                EntityTravelInfo travelInfo = db.EntityTravelInfos.Where(p => p.Id == model.Id).FirstOrDefault();
                if (travelInfo != null)
                {
                    travelInfo.Description = model.Description;

                    //<!--SEO -->
                    travelInfo.Titletag = model.Titletag;
                    travelInfo.Meta_description = model.Meta_description;
                    travelInfo.Meta_keyword = model.Meta_keyword;

                    db.SubmitChanges();
                    TempData["EditSuccessfully"] = "You have successfully changed"; 
                    return RedirectToAction("Edit", "AdminTravelInformation");
                }
                TempData["EditSuccessfully"] = "You have unsuccessfully changed";
                return RedirectToAction("Edit", "AdminTravelInformation");
            }
        }

        #endregion //edit

    }
}
